// 表单验证

/**
 * @param {string} path
 * @returns {Boolean}
 */
export function isExternal(path) {
  return /^(https?:|mailto:|tel:)/.test(path)
}

const name = [
  { required: true, message: '请输入姓名', trigger: 'blur' },
  { min: 2, message: '长度在 2 个字符以上', trigger: 'blur' }
]
const phone = [
  { required: true, message: '请输入手机号', trigger: 'blur' },
  { min: 11, max: 11, message: '手机号长度不正确', trigger: 'blur' }
]
const street = [{ required: true, message: '请输入街道名称', trigger: 'blur' }]
const region = [{ required: true, message: '请选择省市区', trigger: 'blur' }]
const detail = [{ required: true, message: '请输入详细地址', trigger: 'blur' }]
const pkgType = [{ required: true, message: '请选择种类', trigger: 'blur' }]

/**
 * 新包裹表单的校验规则
 * @returns {Arrays} 校验规则
 */
export function newPkgFormRules() {
  const rules = {
    'senderAddress.name': name,
    'senderAddress.phone': phone,
    'senderAddress.street': street,
    'senderAddress.regionCode': region,
    'senderAddress.detail': detail,
    // ----
    'recipientAddress.name': name,
    'recipientAddress.phone': phone,
    'recipientAddress.street': street,
    'recipientAddress.regionCode': region,
    'recipientAddress.detail': detail,
    pkgType: pkgType
  }

  return rules
}

export function editAddressFormRules() {
  return {
    street: street,
    detail: detail,
    name: name,
    phone: phone,
    selectedRegions: region
  }
}
